package com.ghy.text;
import com.ghy.entity.EbProduct;
import com.ghy.mapper.ProductMapper;
import org.apache.ibatis.annotations.Mapper;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
// 导入 spring 的单元测试
@RunWith(SpringJUnit4ClassRunner.class)
// 导入 spring 的配置文件
@ContextConfiguration("classpath:xml/spring-dao.xml")
public class ProductTest {
    @Autowired
    ProductMapper productMapper;
    @Test
    public void testProductPage(){
        int page =1;// 查询第 1 页
        int pageSize= 3;// 每页 3 条
//alt+Enter
        List<EbProduct> products = productMapper.findByPage((page - 1) * pageSize, pageSize);
        System.out.println(products);
    }
    @Test
    public void testSelect(){
        EbProduct one = productMapper.select(669);
        System.out.println(one);
    }

    @Test
    public void testSave(){
        EbProduct ebProduct = new EbProduct();
        ebProduct.setEpName("戒指");
        ebProduct.setEpDescription("饰品");
        ebProduct.setEpPrice(null);
        ebProduct.setEpStock(2000);
        ebProduct.setEpcId(545);
        ebProduct.setEpcChildId(628);
        ebProduct.setEpFileName("612.jpg");
        int num= productMapper.save(ebProduct);
        System.out.println(num);
    }
    @Test
    public void testProductDelete(){
        int result = productMapper.remove(668);
        System.out.println("result:"+result);
    }
    @Test
    public void testNewsUpdate(){
        EbProduct ebProduct = new EbProduct();
        ebProduct.setEpId(616);
        ebProduct.setEpName("戒指");
        ebProduct.setEpDescription("饰品");
        ebProduct.setEpPrice(null);
        ebProduct.setEpStock(2000);
        ebProduct.setEpcId(545);
        ebProduct.setEpcChildId(628);
        ebProduct.setEpFileName("612.jpg");
        int result = productMapper.updateByPrimaryKey(ebProduct);
        System.out.println("result:"+result);

    }
    @Test
    public void testGetMaxPage(){
        Integer maxPage = productMapper.getMaxPage(4);
        System.out.println("maxPage="+maxPage);
    }

}
